package models;

import models.admin.AdminUser;
import models.constants.DeletedStatus;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by liming on 16/7/16.
 * 库存盘点
 */
@Entity
@Table(name = "admin_stock_taking")
public class AdminStockTaking extends BaseModel {
    /**
     * 盘点编号
     */
    @Column(name = "code")
    public String code;

    /**
     * 盘点仓库
     */
    @ManyToOne
    @JoinColumn(name = "admin_warehouse_id")
    public AdminWarehouse adminWarehouse;

    /**
     * 盈亏金额
     * 实际金额和账面金额的差值
     */
    @Column(name = "total_amount")
    public Double totalAmount=0D;

    /**
     * 备注
     */
    @Column(name = "remark")
    public String remark;

    /**
     * 审核人
     */
    @ManyToOne
    @JoinColumn(name = "audit_user_id")
    public AdminUser auditUser;

    /**
     * 审核时间
     */
    @Column(name = "audit_date")
    @Temporal(TemporalType.TIMESTAMP)
    public Date auditDate;

    /**
     * 版本号
     */
    @Version
    public Integer version;

    /**
     * 删除状态
     */
    @Column(name = "deleted_status")
    public DeletedStatus deletedStatus;

    /**
     * 创建时间
     */
    @Transient
    public String createAtStr;

    /**
     * 审核时间
     */
    @Transient
    public String auditDateStr;


    /**
     * 根据Id查询AdminStockTaking
     * param id
     */
    public static AdminStockTaking findByStockTakingID(long id) {
        return AdminStockTaking.find("id=? and deletedStatus=?", id, DeletedStatus.UN_DELETED).first();
    }
}
